/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CLIENT;

import Server.ServerMainChatPanel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Yaniv Kalif
 */
public class ClientMessageListener implements Runnable
{
    ClientConnection _connection;
    BufferedReader in=null;
    ClientMainChatPanel _CreatorP;
    public ClientMessageListener(ClientConnection connection,ClientMainChatPanel Creator) throws IOException
    {
        _connection = connection;
        in = new BufferedReader(new InputStreamReader(_connection.GetConnectedSocket().getInputStream()));
        _CreatorP=Creator;
    }
    public void run()
    {
        try 
        {
            String msg = null;
            System.out.println("client Accept");
            while ((msg = in.readLine()) != null)
            {
                if(in != null)
                {
                    System.out.println("server:" + msg);
                    _CreatorP.RecieveMessage(msg);// send the message to all the users
                }
            }
        }
        catch (IOException ex)
        {
            Logger.getLogger(ClientMessageListener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
